package com.example.bbs.bean;

import java.util.Arrays;

@SuppressWarnings("unused")
public class PostQueryParams implements IComplicatedJavaBean{
/*

    private static final Map<String, Class<?>> classMap = new HashMap<>();
    static {
        classMap.put("searchKeyWordList", PostQueryParams.class);
    }

    @SuppressWarnings("unused")
    public static Map<String, Class<?>> getClassMap() {
        return classMap;
    }
*/
    public static final int SEARCH_TYPE_NO_SEARCH = -1; // no search 会跳过搜索步骤，获取全部结果
    public static final int SEARCH_TYPE_ALL = 0b111; // all 仍然会执行搜索，同样会返回所有的结果
    public static final int SEARCH_TYPE_TITLE = 1;
    public static final int SEARCH_TYPE_CONTENT = 1 << 1;
    public static final int SEARCH_TYPE_AUTHOR = 1 << 2;
    public static final int ORDER_DEFAULT = 0;
    public static final int ORDER_TIME = 1;
    public static final int ORDER_LIKE = 2;

    //筛选信息
    private int page = 0;
    private boolean favoriteOnly = false;//已关注
    private String[] keywords = new String[]{}; // 关键词
    private int searchType = -1;
    private int style = Post.STYLE_ALL; // 查询的 post 类型
    private int order = ORDER_DEFAULT;

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public PostQueryParams nextPage() {
        page += 1;
        return this;
    }

    public boolean isFavoriteOnly() {
        return favoriteOnly;
    }

    public void setFavoriteOnly(boolean favoriteOnly) {
        this.favoriteOnly = favoriteOnly;
    }

    public String[] getKeywords() {
        return keywords;
    }

    public void setKeywords(String[] searchKeyWords) {
        this.keywords = searchKeyWords;
    }

    public int getSearchType() {
        return searchType;
    }

    public void setSearchType(int searchType) {
        this.searchType = searchType;
    }

    public int getStyle() {
        return style;
    }

    public void setStyle(int style) {
        this.style = style;
    }

    public int getOrder() {
        return order;
    }

    public void setOrder(int order) {
        this.order = order;
    }

    // TODO(Low): 监测 QueryParam 变化，避免重复查询
    public boolean equals(PostQueryParams inArgs) {
        return inArgs != null &&
                favoriteOnly == inArgs.favoriteOnly &&
                searchType == inArgs.searchType &&
                style == inArgs.style &&
                order == inArgs.order &&
                Arrays.equals(keywords, inArgs.keywords);
    }
}
